package com.webtair.dump4j.core.impl;

import com.webtair.dump4j.algorithm.PropertiesExtractor;
import com.webtair.dump4j.core.CustomDumper;
import com.webtair.dump4j.core.Item;
import com.webtair.dump4j.exception.ConfigurationException;
import com.webtair.dump4j.objectdump.ObjectDump;
import com.webtair.dump4j.producer.Producer;
import com.webtair.dump4j.writer.Writer;

public class DumperImpl implements CustomDumper{
	private PropertiesExtractor propertiesExtractor;
	private Producer producer;
	private Writer writer;
	private ObjectDump objectDump;
	private int depth=-1;
	private boolean autoClean;

	/**
	 * @return Returns the depth.
	 */
	public int getDepth() {
		return depth;
	}

	/**
	 * @param depth The depth to set.
	 */
	public void setDepth(int depth) {
		this.depth = depth;
	}

	/**
	 * @return Returns the producer.
	 */
	public Producer getProducer() {
		return producer;
	}

	/**
	 * @param producer The producer to set.
	 */
	public void setProducer(Producer producer) {
		this.producer = producer;
	}

	/**
	 * @return Returns the propertiesExtractor.
	 */
	public PropertiesExtractor getPropertiesExtractor() {
		return propertiesExtractor;
	}

	/**
	 * @param propertiesExtractor The propertiesExtractor to set.
	 */
	public void setPropertiesExtractor(PropertiesExtractor propertiesExtractor) {
		this.propertiesExtractor = propertiesExtractor;
	}

	/**
	 * @return Returns the writer.
	 */
	public Writer getWriter() {
		return writer;
	}

	/**
	 * @param writer The writer to set.
	 */
	public void setWriter(Writer writer) {
		this.writer = writer;
	}

	public DumperImpl() {
	}

	public void dump(Object obj) {
		dump(obj,depth);
	}

	public void dump(Object obj, int d) {
		if(propertiesExtractor == null || producer == null || writer == null)
			throw new ConfigurationException("Dumper is badly configured");
		if(d<0)
			throw new ConfigurationException("Depth should be greater or equal to null");
		Item root = propertiesExtractor.extractAllProperties(obj,d);
		objectDump.clear();
		producer.prepareDump(root,objectDump);
		writer.writeDump(objectDump);
	}

	public void setAutoClean(boolean autoClean) {
		this.autoClean = autoClean;
	}

	/**
	 * @return Returns the autoClean.
	 */
	public boolean isAutoClean() {
		return autoClean;
	}

	public ObjectDump getObjectDump() {
		return objectDump;
	}

	public void setObjectDump(ObjectDump objectDump) {
		this.objectDump =objectDump;
	}

	public boolean getAutoClean() {
		return autoClean;
	}
	
	
}
